package _thread_lock._volatile;

public class VolatileDemo2 extends Thread {

    private boolean isRunning = true;

    public boolean isRunning() {
        return isRunning;
    }

    public void setRunning(boolean running) {
        isRunning = running;
    }

    public void run(){
        System.out.println("进入run方法..");
        int i=0;
        while (isRunning) {
            i++;
//            ArrayList aaa = new ArrayList();
//            aaa.add(1);
//            System.out.println("i:" + i);
        }
        System.out.println(i);

        System.out.println("isRunning:" + isRunning);
        System.out.println("线程终止..");
    }

    public static void main(String[] args) throws InterruptedException {
        VolatileDemo2 volatileDemo2 = new VolatileDemo2();
        volatileDemo2.start();

        Thread.sleep(3000);
        volatileDemo2.setRunning(false);
        System.out.println("set false-->" + volatileDemo2.isRunning());
    }
}
